project(
    'slsqp',
    'fortran',
    version : '1.2.3',
    license : 'BSD-3-Clause',
    meson_version : '>=0.60.0',
    default_options : [
        'buildtype=debugoptimized',
        'fortran_std=f2008',
        'default_library=both',
    ],
)

slsqp_src_filenames = []
slsqp_src = files()
subdir('src')
slsqp_lib = library(
    meson.project_name(),
    slsqp_src,
    version : meson.project_version(),
    install : true,
)

# subdir('test')

slsqp_inc = slsqp_lib.private_dir_include()
slsqp_dep = declare_dependency(
    link_with : slsqp_lib,
    include_directories : slsqp_inc,
)

slsqp_lic = files('LICENSE')
install_data(
    slsqp_lic,
    install_dir : join_paths(get_option('prefix'), 'share', 'licenses', meson.project_name()),
)

if host_machine.system() == 'windows'
    symbols_file = 'lib'+meson.project_name()+'-'+meson.project_version().split('.')[0]+'.dll.symbols'
    obj_suffix = '.obj'
else
    symbols_file = 'lib'+meson.project_name()+'.so.'+meson.project_version()+'.symbols'
    obj_suffix = '.o'
endif

slsqp_obj = []
foreach source: slsqp_src_filenames
    slsqp_obj += 'src_'+source+obj_suffix
endforeach

install_subdir(
    slsqp_lib.full_path()+'.p',
    install_dir: 'include'/meson.project_name(),
    strip_directory: true,
    exclude_files: [
        'depscan.dd',
        meson.project_name()+'-deps.json',
        symbols_file,
        meson.project_name()+'.dat',
        slsqp_obj,
    ]
)

pkg = import('pkgconfig')
pkg.generate(
    name : meson.project_name(),
    description : 'Modern Fortran Edition of the SLSQP Optimizer',
    version : meson.project_version(),
    libraries : slsqp_lib,
    subdirs : meson.project_name(),
)
